<script type="text/javascript">
    $(function () {
        $('#system_menu_form_add_parentid').combotree({url: "/b/system/menu-tree"});
        $.formValidator.initConfig({
            formID: "system_menu_add_dialog_form",
            onError: function (msg) {
            },
            onSuccess: systemMenuAddDialogFormSubmit,
            submitAfterAjaxPrompt: '有数据正在异步验证，请稍等...',
            inIframe: true
        });
        $("#system_menu_form_add_parentid").formValidator({
            onShow: "请选择上级菜单",
            onFocus: "上级菜单不能为空"
        }).inputValidator({min: 0, type: 'value', onError: "上级菜单不能为空"}).defaultPassed();
        $("#system_menu_form_add_name").formValidator({
            onShow: "请输入菜单名称",
            onFocus: "菜单名称不能为空",
            onCorrect: "输入正确"
        }).inputValidator({
            min: 1,
            empty: {leftEmpty: false, rightEmpty: false, emptyError: '菜单名称不能有空格'},
            onError: "菜单名称不能为空"
        }).ajaxValidator({
            type: "post",
            url: "/b/system/menu-check",
            data: {
                name: function () {
                    return $("#system_menu_form_add_name").val()
                }
            },
            datatype: "json",
            async: 'false',
            success: function (res) {
                var json = $.parseJSON(res);
                return json.errcode === 0;
            },
            onError: "菜单名称已存在",
            onWait: "请稍候..."
        });
        $("#system_menu_form_add_c").formValidator({onShow: "请输入模块名", onFocus: "模块名不能少于2个字符"}).inputValidator({
            min: 2,
            empty: {leftEmpty: false, rightEmpty: false, emptyError: '模块名不能有空格'},
            onError: "模块名不能少于2个字符"
        }).regexValidator({
            regExp: "^([a-z][a-z1-9]+)+$",
            param: "",
            dataType: "string",
            onError: "必须以字母开头"
        });
        $("#system_menu_form_add_a").formValidator({onShow: "请输入方法名", onFocus: "方法名不能少于2个字符"}).inputValidator({
            min: 2,
            empty: {leftEmpty: false, rightEmpty: false, emptyError: '方法名不能有空格'},
            onError: "方法名不能少于2个字符"
        }).regexValidator({
            regExp: "^[a-z][a-z1-9_]+([A-Z][a-z1-9]+)?$",
            param: "",
            dataType: "string",
            onError: "必须为首字母小写的驼峰法命名"
        });
    })
    function systemMenuAddDialogFormSubmit() {
        $.post('/b/system/menu-add', $("#system_menu_add_dialog_form").serialize(), function (res) {
            if (res.errcode) {
                $.messager.alert('提示信息', res.errmsg, 'error');
            } else {
                $.messager.alert('提示信息', res.errmsg, 'info');
                $('#system_menu_add_dialog').dialog('close');
                systemMenuRefresh();
            }
        }
    )
    }
</script>
<form id="system_menu_add_dialog_form">
    <table class="dialogtable">
        <tr>
            <td width="100">上级菜单：</td>
            <td><input id="system_menu_form_add_parentid" name="parentid" class="easyui-combotree" value="0" style="width:180px;height:26px"/></td>
            <td>
                <div id="system_menu_form_add_parentidTip"></div>
            </td>
        </tr>
        <tr>
            <td>菜单名称：</td>
            <td><input id="system_menu_form_add_name" name="name" type="text" style="width:178px;height:22px"/>
            </td>
            <td>
                <div id="system_menu_form_add_nameTip"></div>
            </td>
        </tr>
        <tr>
            <td>模块名：</td>
            <td><input id="system_menu_form_add_c" name="c" type="text" style="width:178px;height:22px"/></td>
            <td>
                <div id="system_menu_form_add_cTip"></div>
            </td>
        </tr>
        <tr>
            <td>方法名：</td>
            <td><input id="system_menu_form_add_a" name="a" type="text" style="width:178px;height:22px"/></td>
            <td>
                <div id="system_menu_form_add_aTip"></div>
            </td>
        </tr>
        <tr>
            <td>附加参数：</td>
            <td><input class="input_show" name="data" type="text" style="width:178px;height:22px"/></td>
            <td></td>
        </tr>
        <tr>
            <td>是否显示菜单：</td>
            <td colspan="2">
                <label><input name="display" value="1" type="radio" checked/>是</label>
                <label><input name="display" value="0" type="radio"/>否</label>
            </td>
        </tr>
    </table>
</form>
